﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Collections;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SummaryForm.xaml
    /// </summary>

    public partial class YCAMDPLAN
    {         
        public void AutoRun(DoWorkEventArgs e)
        {
            DataSet SReturn = new DataSet();
            DataSet SResult = new DataSet();
            try
            {
                switch (JobType)
                {
                    case "LOADREQ":
                        SResult = m_Data.LoadGXDECKData();
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            SetData.Clear();
                            SetData.Merge(SResult); 
                        }));
                        break;
                    case "AUTOEK":
                        SResult = m_Data.CreateTempEKPOS(tpEKPOS);
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            tpEKPOS.Clear();
                            SetTmp.Clear();
                            Set4ITX.ICC_EKPOS.Clear();
                            Set4ITX.Merge(SResult);
                            btnITXPurchase.IsEnabled = true;
                        }));
                        break;
                    case "PUSH2ITX":
                        ITXPurchase();
                        break;
                    case "LOADXDECK":
                        ArrayList args = (ArrayList)e.Argument;
                        SResult = m_Data.LoadXDECKData((DataRow)args[0], (bool)args[1]);
                        this.Dispatcher.Invoke(new Action(() =>
                        {
                            pSType = "";
                            Set4ITX.ICC_STOCK.Clear();
                            Set4ITX.ICC_EKPOS.Clear();
                            SetData.ABPOS.Clear();
                            SetData.ICC_ABAUFM.Clear();
                            //MBST EKPOS MDECK ABPOS ICC_ABAUFM
                            if (SResult.Tables.Contains("ICC_STOCK"))
                            {
                                Set4ITX.Merge(SResult.Tables["ICC_STOCK"]);
                            }
                            if (SResult.Tables.Contains("ICC_EKPOS"))
                            {
                                Set4ITX.Merge(SResult.Tables["ICC_EKPOS"]);
                            }
                            if (SResult.Tables.Contains("MDECK"))
                            {
                                Set4ITX.Merge(SResult.Tables["MDECK"]);
                            }
                            if (SResult.Tables.Contains("ABPOS"))
                            {
                                SetData.Merge(SResult.Tables["ABPOS"]);
                            }
                            if (SResult.Tables.Contains("ICC_ABAUFM"))
                            {
                                SetData.Merge(SResult.Tables["ICC_ABAUFM"]);
                            }
                            if (vwITXXDECK.View != null)
                            {
                                vwITXXDECK.View.MoveCurrentToFirst();
                            }
                            if (vwITXABPOS.View != null)
                            {
                                vwITXABPOS.View.MoveCurrentToFirst();
                            }
                        }));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
    }
}